<template>
    <div class="header">
        <!-- 折叠按钮 -->
        <!-- <div class="collapse-btn" @click="collapseChage">
            <i v-if="!collapse" class="el-icon-s-fold"></i>
            <i v-else class="el-icon-s-unfold"></i>
        </div>-->
        <div class="logo">
            <p class="logoTitle1">项目管理系统</p>
            <p class="logoTitle2">形象进度管理子系统</p>
        </div>
        <div class="header-right">
            <div class="date">{{ nowDate + ' ' + nowTime }}</div>
            <!-- <div class="header-user-con"> -->
            <!-- 全屏显示 -->
            <!-- <div class="btn-fullscreen" @click="handleFullScreen">
                    <el-tooltip effect="dark" :content="fullscreen ? `取消全屏` : `全屏`" placement="bottom">
                        <i style="color:#333" class="el-icon-rank"></i>
                    </el-tooltip>
            </div>-->
            <!-- 消息中心 -->
            <!-- <div class="btn-bell">
                    <el-tooltip
                        effect="dark"
                        :content="message?`有${message}条未读消息`:`消息中心`"
                        placement="bottom"
                    >
                        <router-link to="/tabs">
                            <i class="el-icon-bell"></i>
                        </router-link>
                    </el-tooltip>
                    <span class="btn-bell-badge" v-if="message"></span>
            </div>-->
            <!-- 用户头像 -->

            <!-- 用户名下拉菜单 -->
            <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                <span class="el-dropdown-link">
                    <span v-if="type == 0">超级管理员</span>
                    <span v-else-if="type == 1">生产运营部</span>
                    <span v-else-if="type == 2">事业部</span>
                    <span v-else-if="type == 3">项目部</span>
                    <span v-else-if="type == 4">公司领导层</span>
                    <span v-else-if="type == 'null'">{{userName}}</span>
                    <i
                        style="color:#333333;margin-left:18px;font-size:22px"
                        class="el-icon-caret-bottom"
                    ></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                    <!-- <a href="https://github.com/lin-xin/vue-manage-system" target="_blank"> -->
                    <el-dropdown-item command="changePassword">修改密码</el-dropdown-item>
                    <!-- </a> -->
                    <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </div>
    <!-- </div> -->
</template>
<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            fullscreen: false,
            name: 'linxin',
            message: 2,
            nowDate: '', // 当前日期
            nowTime: '', // 当前时间
            type: '',
            userName:''
        };
    },
    created() {
        //声明一个变量指向Vue实例this，保证作用域一致
        this.timer = setInterval(function() {
            this.currentTime = //修改数据date
                new Date().getFullYear() +
                '年' +
                (new Date().getMonth() + 1) +
                '月' +
                new Date().getDate() +
                '日' +
                new Date().getHours() +
                ':' +
                new Date().getMinutes() +
                ': ' +
                new Date().getSeconds();
        }, 1000);
        this.username();
    },
    methods: {
        //判断用户类型
        username() {
            this.type = localStorage.getItem('type');
            this.userName=localStorage.getItem('projectid')
        },
        // 用户名下拉菜单选择事件
        handleCommand(command) {
            if (command == 'loginout') {
                this.$confirm('是否退出当前登录账号', {
                    customClass: 'newObjectConfirm',
                    center: true,
                    showClose: false,
                    cancelButtonClass: 'logoutCancel',
                    confirmButtonClass: 'logoutConfirm'
                }).then(() => {
                    this.$message({
                                    type: 'success',
                                    message: '退出成功'
                                });
                        localStorage.clear();
                        this.$router.push('/Login');
                    })
                    .catch(() => {});
            } else if (command == 'changePassword') {
                this.$router.push('/editPassword');
            }
        },
        // 侧边栏折叠
        collapseChage() {
            this.collapse = !this.collapse;
            bus.$emit('collapse', this.collapse);
        },
        // 全屏事件
        handleFullScreen() {
            let element = document.documentElement;
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            } else {
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen();
                }
            }
            this.fullscreen = !this.fullscreen;
        },
        currentTime() {
            setInterval(this.getDate, 1000);
        },
        getDate() {
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1;
            let dd = new Date().getDate();
            let hh = new Date().getHours();
            let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
            let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
            this.nowTime = hh + ':' + mf + ':' + ss;
            this.nowDate = yy + '年' + mm + '月' + dd + '日';
        }
    },
    mounted() {
        // if (document.body.clientWidth < 1500) {
        //     this.collapseChage();
        // }
        this.currentTime();
    },
    beforeDestroy() {
        if (this.getDate) {
            clearInterval(this.getDate); // 在Vue实例销毁前，清除时间定时器
        }
    }
};
</script>
<style scoped>
.header {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 80px;
    font-size: 22px;
    color: #fff;
    background-color: #fff;
    box-shadow: 0px 11px 14px -5px rgba(0, 0, 0, 0.05);
}
.collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;
    line-height: 80px;
    background-color: #003f89;
    border-bottom: 1px solid #003f89;
}
.header .logo {
    float: left;
    width: 240px;
    height: 80px;
    padding: 0 0 0 30px;
    box-sizing: border-box;
    background-color: #003f89;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: none;
    box-sizing: border-box;
}
.header .logo::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 176px;
}
.logoTitle1 {
    height: 17px;
    font-size: 12px;
    font-family: PingFangSC-Light, PingFang SC;
    font-weight: 300;
    color: rgba(255, 255, 255, 1);
    line-height: 17px;
    width: 180px;
}
.logoTitle2 {
    width: 180px;
    height: 28px;
    font-size: 20px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
    line-height: 28px;
}

.header-right {
    float: right;
    padding-right: 50px;
    box-sizing: border-box;
}
.header-user-con {
    display: flex;
    height: 80px;
    align-items: center;
}
.btn-fullscreen {
    transform: rotate(45deg);
    margin-right: 5px;
    font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
    position: relative;
    width: 30px;
    height: 30px;
    text-align: center;
    border-radius: 15px;
    cursor: pointer;
}
.btn-bell-badge {
    position: absolute;
    right: 0;
    top: -2px;
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #f56c6c;
    color: #fff;
}
.btn-bell .el-icon-bell {
    color: #fff;
}
.user-name {
    margin-left: 122px;
    font-size: 16px;
    line-height: 80px;
}
.user-avator {
    margin-left: 20px;
}
.user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.el-dropdown-link {
    color: #004fab;
    cursor: pointer;
    line-height: 22px;
}
.el-dropdown-menu__item {
    text-align: center;
}
.header-right .date {
    float: left;
}
.date {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(153, 153, 153, 1);
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(153, 153, 153, 1);
    line-height: 20px;
    margin-top: 30px;
}
.user-name::before {
    content: '欢迎您，';
    font-weight: 500;
    color: rgba(51, 51, 51, 1);
}
.logoutCancel{
    width:90px;
height:35px;
background:rgba(255,255,255,0.2);
border-radius:5px;
font-size:16px;
font-family:PingFangSC-Regular,PingFang SC;
font-weight:400;
color:rgba(255,255,255,1);
}
.logoutConfirm{
    width:90px;
height:35px;
background:rgba(0,79,171,1);
border-radius:5px;
font-size:16px;
font-family:PingFangSC-Regular,PingFang SC;
font-weight:400;
color:rgba(255,255,255,1);
}


</style>
